package com.sky.controller;

import com.sky.entity.ArticleSort;
import com.sky.result.Result;
import com.sky.service.ArticleSortService;
import com.sky.vo.ArticleSortVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 文章分类
 */
@RestController
@RequestMapping("/article/sort")
@Slf4j
@Api(tags = "文章分类相关接口")
public class ArticleSortController {

    @Autowired
    private ArticleSortService articleSortService;

    /**
     * 文章分类查询全部
     * @return
     */
    @ApiOperation("文章分类查询全部")
    @GetMapping("/select")
    @CrossOrigin("http://localhost:5173")
    public Result<List<ArticleSortVO>> selectArticleSort(){
        log.info("文章分类查询全部");
        List<ArticleSortVO> articleSortVOS = new ArrayList<>();
        articleSortVOS = articleSortService.selectArticleSort();
        return Result.success(articleSortVOS);
    }


    /**
     * 文章分类新添
     * @param articleSort
     * @return
     */
    @ApiOperation("文章分类新添")
    @PostMapping("/insert")
    @CrossOrigin("http://localhost:5173")
    public Result insertArticleSort(@RequestBody ArticleSort articleSort){
        log.info("文章分类新添:{}",articleSort);
        articleSortService.insertArticleSort(articleSort);
        return Result.success("添加成功");
    }



    /**
     * 文章分类修改
     * @param articleSort
     * @return
     */
    @ApiOperation("文章分类修改")
    @PutMapping("/update")
    @CrossOrigin("http://localhost:5173")
    public Result updateArticleSort(@RequestBody ArticleSort articleSort){
        log.info("文章分类修改:{}",articleSort);
        articleSortService.updateArticleSort(articleSort);
        return Result.success("修改成功");
    }


    /**
     * 文章分类删除
     * @param id
     * @return
     */
    @ApiOperation("文章分类删除")
    @DeleteMapping("/delete")
    @CrossOrigin("http://localhost:5173")
    public Result deleteArticleSort(@RequestParam Long id){
        log.info("文章分类删除:{}",id);
        articleSortService.deleteArticleSort(id);
        return Result.success("删除成功");
    }


}
